package com.spring.demo8.eg12;

import org.junit.Test;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author vhans
 */
@Configuration
public class DestroyTest {
    @Bean(destroyMethod = "customDestroy")
    public ServiceC serviceC() {
        return new ServiceC();
    }

    @Test
    public void test() {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
        context.register(DestroyTest.class);

        System.out.println("准备启动容器");
        context.refresh();
        System.out.println("容器启动完毕");

        System.out.println("serviceC" + context.getBean(ServiceC.class));

        System.out.println("准备关闭容器");
        context.close();
        System.out.println("容器关闭完毕");
    }
}
